<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>编辑鸡蛋数量</title>
	<%@ include file="/view/common/tags.jsp"%>
</head>
<body>
	<div class="well well_p" >
		<sk:form method="post" cssClass="form-horizontal" action="${sysManagerV1}/pubgClub/addOrReduceEgg" id="saveAndUpdateForm" target="_parent">
			<div class="form-group">
				<label class="col-xs-3 text-right">
					<c:if test="${opera == 'add'}">加</c:if><c:if test="${opera == 'reduce'}">减</c:if>鸡蛋数量:
				</label>
				<div class="col-xs-5">
					<input type="text" class="form-control" name="clubBalance" id="clubBalance" value="" maxlength = "7" placeholder="请输入鸡蛋数量，最大100万">
					<input type="hidden" id="rowId" name="rowId" value="${pubgClub.rowId }">
					<input type="hidden" id="opera" name="opera" value="${opera }">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-3 text-right">当前鸡蛋数量:</label>
				<div class="col-xs-5">${empty pubgClub.clubBalance ? 0 : pubgClub.clubBalance}</div>
			</div>
			<input type="hidden" id="isReCommit" value="0">
		</sk:form>
	</div>
</body>
   <%@ include file="/view/common/footer.jsp"%>
   <script type="text/javascript">
   //加/减鸡蛋
   function addOrReduceEgg(){
	    var rowId = $('#rowId').val();
	    if (rowId != null && rowId > 0) {
            var clubBalance = $('#clubBalance').val();
            if (clubBalance == null || clubBalance == '') {
                layer.msg("鸡蛋数量不能为空!");
                return;
            }
            if (!CheckUtil.isInt(clubBalance, "+") && !CheckUtil.isFloat(clubBalance, "+")) {
                layer.msg("鸡蛋数量只能为正数!");
                return;
            }
            if (parseFloat(clubBalance) >1000000) {
                layer.msg("鸡蛋数量不能大于100W!");
                return;
            }
            var opera = "${opera}";
            if (opera == "reduce") {//减鸡蛋操作处理数据
                clubBalance = 0 - parseFloat(clubBalance);
            }
            var sumEgg = parseFloat(clubBalance);//加/减鸡蛋后数量
            var oldClubBalance = "${empty pubgClub.clubBalance ? 0 : pubgClub.clubBalance}";//原鸡蛋数量
            if (oldClubBalance != null && oldClubBalance >=0 ) {
                sumEgg = sumEgg + parseFloat(oldClubBalance);
            }
            if (sumEgg < 0) {
                layer.msg("俱乐部余额不能为负数!");
                return;
            }
            if ($("#isReCommit").val() == 0) {
                $("#isReCommit").val(1);
                $("#saveAndUpdateForm").submit();
            }
		}
	}
   </script>
</html>